use "${clean}newspaper_analysis.dta", clear
keep if north == 1 | south == 1

// recoding Alexandria, VA to the South (technically part of DC until 1844)
replace south = 1 if city == "Alexandria"
replace north = 0 if city == "Alexandria"
replace state = "Virginia" if city == "Alexandria"

// dropping DC as a border area
drop if state == "District Of Columbia"

// standardizing variables
egen county_surban = std(county_urban_percent)
egen county_srugged = std(county_ruggedness)
egen county_spostoffice = std(county_postoffice_area)

// keeping the sample consistent
cap drop sample
gen sample = 1
foreach var of varlist $county_npcontrols {
	replace sample = . if `var' == .
}



// estimates 1860
xtset pub_id


foreach y in 1860 {

preserve

gen period = year > `y'
replace year = year - `y'

estimates clear	

qui eststo: xtreg singular c.year##i.period##i.north if sample == 1, re cluster(pub_id)
estadd local fe "No"

qui eststo: xtreg singular c.year##i.period##i.north if sample == 1, fe cluster(pub_id)
estadd local fe "Publication"

qui eststo: xtreg singular c.year##i.period##i.north ${county_npcontrols} if sample == 1, re cluster(pub_id)
estadd local fe "No"

qui eststo: xtreg singular c.year##i.period##i.north ${county_npcontrols} if sample == 1, fe cluster(pub_id)
estadd local fe "Publication"



// table
esttab est* using "${output}TabD3_np_ns_`y'_fulltable.tex", replace ///
	b(%8.3f) se(%8.3f) ///
	starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	scalars("fe Fixed Effects") ///
	keep( ///
		year ///
		1.period ///
		1.north ///
		1.period#c.year ///
		1.north#c.year ///
		1.period#1.north ///
		1.period#1.north#c.year ///
		county_surban county_spostoffice county_srugged county_anyriver county_anycanal _cons ///
		) ///
	order( ///
		year ///
		1.period ///
		1.north ///
		1.period#c.year ///
		1.north#c.year ///
		1.period#1.north ///
		1.period#1.north#c.year ///
		county_surban county_spostoffice county_srugged county_anyriver county_anycanal _cons ///
		) ///
	coeflabels( ///
		year "Year" ///
		1.period "After `y'" ///
		1.north "North" ///
		1.period#c.year "Year $\times$ After `y'" ///
		1.north#c.year "Year $\times$ North" ///
		1.period#1.north "After `y' $\times$ North" ///
		1.period#1.north#c.year "Year $\times$ After `y' $\times$ North" ///
		county_surban "County \% Urban (std)" ///
		county_spostoffice "Post Office Density (std)" ///
		county_srugged "Terrain Ruggedness (std)" ///
		county_anyriver "County on River" ///
		county_anycanal "County on Canal" ///
		_cons "Constant" ///
		) ///
	nodepvars nomtitles nonotes ///
	nogaps nolines posthead(\midrule) prefoot(\midrule) postfoot("\bottomrule \end{tabular}}") ///
	tex compress	
	
restore	
}



// estimates 1865
xtset pub_id


foreach y in 1865 {

preserve

gen period = year > `y'
replace year = year - `y'

estimates clear	

qui eststo: xtreg singular c.year##i.period##i.north if sample == 1, re cluster(pub_id)
estadd local fe "No"

qui eststo: xtreg singular c.year##i.period##i.north if sample == 1, fe cluster(pub_id)
estadd local fe "Publication"

qui eststo: xtreg singular c.year##i.period##i.north ${county_npcontrols} if sample == 1, re cluster(pub_id)
estadd local fe "No"

qui eststo: xtreg singular c.year##i.period##i.north ${county_npcontrols} if sample == 1, fe cluster(pub_id)
estadd local fe "Publication"



// table
esttab est* using "${output}TabD4_np_ns_`y'_fulltable.tex", replace ///
	b(%8.3f) se(%8.3f) ///
	starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	scalars("fe Fixed Effects") ///
	keep( ///
		year ///
		1.period ///
		1.north ///
		1.period#c.year ///
		1.north#c.year ///
		1.period#1.north ///
		1.period#1.north#c.year ///
		county_surban county_spostoffice county_srugged county_anyriver county_anycanal _cons ///
		) ///
	order( ///
		year ///
		1.period ///
		1.north ///
		1.period#c.year ///
		1.north#c.year ///
		1.period#1.north ///
		1.period#1.north#c.year ///
		county_surban county_spostoffice county_srugged county_anyriver county_anycanal _cons ///
		) ///
	coeflabels( ///
		year "Year" ///
		1.period "After `y'" ///
		1.north "North" ///
		1.period#c.year "Year $\times$ After `y'" ///
		1.north#c.year "Year $\times$ North" ///
		1.period#1.north "After `y' $\times$ North" ///
		1.period#1.north#c.year "Year $\times$ After `y' $\times$ North" ///
		county_surban "County \% Urban (std)" ///
		county_spostoffice "Post Office Density (std)" ///
		county_srugged "Terrain Ruggedness (std)" ///
		county_anyriver "County on River" ///
		county_anycanal "County on Canal" ///
		_cons "Constant" ///
		) ///
	nodepvars nomtitles nonotes ///
	nogaps nolines posthead(\midrule) prefoot(\midrule) postfoot("\bottomrule \end{tabular}}") ///
	tex compress	
	
restore
}

/*
// estimates
xtset pub_id


foreach y in 1860 1865 {

preserve

gen period = year > `y'
replace year = year - `y'

estimates clear	

qui eststo: xtreg singular c.year##i.period##i.north if sample == 1, re cluster(pub_id)
estadd local fe "No"

qui eststo: xtreg singular c.year##i.period##i.north if sample == 1, fe cluster(pub_id)
estadd local fe "Publication"

qui eststo: xtreg singular c.year##i.period##i.north ${county_npcontrols} if sample == 1, re cluster(pub_id)
estadd local fe "No"

qui eststo: xtreg singular c.year##i.period##i.north ${county_npcontrols} if sample == 1, fe cluster(pub_id)
estadd local fe "Publication"



// table
esttab est* using "${output}np_ns_`y'_fulltable.tex", replace ///
	b(%8.3f) se(%8.3f) ///
	starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	scalars("fe Fixed Effectss") ///
	keep( ///
		year ///
		1.period ///
		1.north ///
		1.period#c.year ///
		1.north#c.year ///
		1.period#1.north ///
		1.period#1.north#c.year ///
		county_surban county_spostoffice county_srugged county_anyriver county_anycanal _cons ///
		) ///
	order( ///
		year ///
		1.period ///
		1.north ///
		1.period#c.year ///
		1.north#c.year ///
		1.period#1.north ///
		1.period#1.north#c.year ///
		county_surban county_spostoffice county_srugged county_anyriver county_anycanal _cons ///
		) ///
	coeflabels( ///
		year "Year" ///
		1.period "After `y'" ///
		1.north "North" ///
		1.period#c.year "Year $\times$ After `y'" ///
		1.north#c.year "Year $\times$ North" ///
		1.period#1.north "After `y' $\times$ North" ///
		1.period#1.north#c.year "Year $\times$ After `y' $\times$ North" ///
		county_surban "County \% Urban (std)" ///
		county_spostoffice "Post Office Density (std)" ///
		county_srugged "Terrain Ruggedness (std)" ///
		county_anyriver "County on River" ///
		county_anycanal "County on Canal" ///
		_cons "Constant" ///
		) ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot("\bottomrule \end{tabular}}") ///
	tex compress	

restore	
}
